"""
@Author  : 康帅
@Time    : 2021/1/25 15:45
@Function: 取交集使用列表推导式处理速度更快
"""


import itertools


def intersect(seq1, seq2):
    a = []
    for x in seq1:
        if x in seq2:
            a.append(x)
    return a


def list_data():
    """
    列表调优写法
    :return:
    """
    l1 = [1, 2]
    l2 = [3, 4]
    l3 = [4, 5]
    l_sum = sum((l1, l2, l3), [])
    print(l_sum)  # [1, 2, 3, 4, 4, 5]


def list_itertools():
    """
    列表辗平:
        将多个列表合并为一个大列表
    :return: []
    """
    a_list = [[1, 2], [3, 4], [5, 6]]
    print(list(itertools.chain.from_iterable(a_list)))  # [1, 2, 3, 4, 5, 6]
    # 或者
    print(list(itertools.chain(*a_list)))  # [1, 2, 3, 4, 5, 6]


if __name__ == '__main__':
    s1 = 'spam'
    s2 = 'scam'
    c = intersect(s1, s2)
    print(c)
    x = intersect([1, 2, 3], (1, 4))
    print(x)

    data = [x for x in s1 if x in s2]
    print(data)

    list_itertools()
